home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Pascal V7.0 / TVFM.ZIP / TREEWIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-30  |  5.6 KB  |  210 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. unit TreeWin;  { Tree window object }
  9.  
  10. {$X+,V-}
  11.  
  12. interface
  13.  
  14. uses Drivers, Objects, Views, FileView, DirView;
  15.  
  16. type
  17.   PTreeWindow = ^TTreeWindow;
  18.   TTreeWindow = object(TWindow)
  19.     DirView: PDirectoryViewer;
  20.     FileView: PFileView;
  21.     procedure SizeLimits(var Min, Max: TPoint); virtual;
  22.     procedure HandleEvent(var Event: TEvent); virtual;
  23.     function GetTitle(Width: Integer): TTitleStr; virtual;
  24.   end;
  25.  
  26. procedure InsertTreeWindow(Drive: Char);
  27.  
  28. implementation
  29.  
  30. uses Globals, Dos, Equ, Tools, Dialogs, App, Assoc, InfoView;
  31.  
  32. { TTreeWindow }
  33.  
  34. procedure TTreeWindow.SizeLimits(var Min, Max: TPoint);
  35. begin
  36.   inherited SizeLimits(Min, Max);
  37.   Min.X := 48;
  38. end;
  39.  
  40. function TTreeWindow.GetTitle(Width: Integer): TTitleStr;
  41. begin
  42.   GetTitle := FileView^.Dir + '\' + ConfigRec.FileMask;
  43. end;
  44.  
  45. procedure TTreeWindow.HandleEvent(var Event: TEvent);
  46. var
  47.   F: PFileRec;
  48.   D: PDirectory;
  49.   CurrentFile: PathStr;
  50. begin
  51.   inherited HandleEvent(Event);
  52.  
  53.   if Event.What = evBroadcast then
  54.   begin
  55.     case Event.Command of
  56.       cmInvalidDir :
  57.         begin
  58.           D := DirView^.GetNode(DirView^.Foc);
  59.           if PString( Event.InfoPtr )^ = D^.Dir^ then
  60.             Message(FileView, evBroadcast, cmRescan, nil);
  61.         end;
  62.       cmTopWindow:
  63.         ClearEvent(Event);
  64.       cmFileListFocused :
  65.         if (Current = PView(FileView)) and (FileView^.List^.Count > 0) then
  66.           ClearEvent(Event);
  67.       cmCloseAll :
  68.         Close;
  69.     end;
  70.   end;
  71.  
  72.   if Event.What = evCommand then
  73.   begin
  74.     { Get the full filename of the current file }
  75.     if (Current = PView(FileView)) and (FileView^.List^.Count > 0) then
  76.     begin
  77.       D := DirView^.GetNode(DirView^.Foc);
  78.       F := FileView^.List^.At(FileView^.Focused);
  79.       CurrentFile := D^.Dir^ + '\' + F^.Name + F^.Ext;
  80.  
  81.       case Event.Command of
  82.         cmViewAsHex : ViewAsHex(CurrentFile);
  83.         cmViewAsText : ViewAsText(CurrentFile);
  84.         cmViewCustom : ViewCustom(CurrentFile);
  85.         cmExecute : ExecuteFile(CurrentFile);
  86.         cmAssociate: Associate(F^.Ext);
  87.         cmCopy : HandleFileCopy(D^.Dir^, FileView^.List, FileView^.Focused);
  88.         cmDelete : HandleFileDelete(D^.Dir^, FileView^.List, FileView^.Focused);
  89.         cmRename : RenameFile(D^.Dir^, F);
  90.         cmChangeAttr : ChangeAttr(D^.Dir^, F);
  91.         else Exit;
  92.       end; { case }
  93.       ClearEvent(Event);
  94.     end;
  95.   end;
  96.  
  97.  
  98. end;
  99.  
  100.  
  101. procedure InsertTreeWindow(Drive: Char);
  102. var
  103.   Bounds, R: TRect;
  104.   W, TopWin: PTreeWindow;
  105.   vSB, hSB: PScrollBar;
  106.   PRoot: PString;
  107.   Root: String[2];
  108.   S: string[40];
  109.   D: PDialog;
  110.   Width: Integer;
  111. begin
  112.   Root := Drive + ':';
  113.   PRoot := @Root;
  114.  
  115.   FormatStr(S, RezStrings^.Get(sScanning), PRoot);
  116.   D := WaitDialog(S);
  117.   Desktop^.Insert(D);
  118.  
  119.   Bounds.Assign(0,0,75,16);
  120.   W := New(PTreeWindow, Init(Bounds, Root, wnNoNumber));
  121.   with W^ do
  122.   begin
  123.     Options := Options or ofTileable;
  124.     GetExtent(Bounds);
  125.  
  126.     Width := Bounds.B.X - Bounds.A.X;
  127.     Bounds.B.X := Width div 3;
  128.  
  129.     R.Assign(Bounds.B.X-1, Bounds.A.Y+1, Bounds.B.X, Bounds.B.Y-1);
  130.     vSB := New(PScrollBar, Init(R));
  131.     vSB^.Options := vSB^.Options or ofPostProcess;
  132.     vSB^.GrowMode :=  gfGrowHiY;
  133.     Insert(vSB);
  134.  
  135.     R.Assign(Bounds.A.X+2, Bounds.B.Y-1, Bounds.B.X-2, Bounds.B.Y);
  136.     hSB := New(PScrollBar, Init(R));
  137.     hSB^.Options := hSB^.Options or ofPostProcess;
  138.     hSB^.GrowMode := gfGrowHiY + gfGrowLoY;
  139.     Insert(hSB);
  140.  
  141.     Bounds.Grow(-1,-1);
  142.     DirView := New(PDirectoryViewer, Init(Bounds, hSB, vSB,
  143.       New(PDirectory, Init(Root))));
  144.  
  145.     with DirView^ do
  146.     begin
  147.       Options := Options or (ofFramed or ofFirstClick);
  148.       Adjust(GetRoot, True);
  149.       GrowMode := gfGrowHiY;
  150.       Update;
  151.     end;
  152.     Insert(DirView);
  153.  
  154.     { Create the file viewer }
  155.     GetExtent(Bounds);
  156.  
  157.     Bounds.A.X := Bounds.A.X + (Width div 3) - 1;
  158.     Dec(Bounds.B.Y,3);
  159.  
  160.     R.Assign(Bounds.B.X-1, Bounds.A.Y+1, Bounds.B.X, Bounds.B.Y-1);
  161.     vSB := New(PScrollBar, Init(R));
  162.     vSB^.Options := vSB^.Options or ofPostProcess;
  163.     vSB^.GrowMode :=  gfGrowHiY + gfGrowLoX + gfGrowHiX;
  164.     Insert(vSB);
  165.  
  166.     R.Assign(Bounds.A.X+2, Bounds.B.Y-1, Bounds.B.X-2, Bounds.B.Y);
  167.     hSB := New(PScrollBar, Init(R));
  168.     hSB^.Options := hSB^.Options or ofPostProcess;
  169.     hSB^.GrowMode := gfGrowHiY + gfGrowLoY + gfGrowHiX;
  170.     hSB^.SetRange(0, 40);
  171.     Insert(hSB);
  172.  
  173.     Bounds.Grow(-1,-1);
  174.     FileView := New(PFileView, Init(Bounds, hSB, vSB));
  175.     FileView^.GrowMode := gfGrowHiY + gfGrowHiX;
  176.     FileView^.Options := FileView^.Options or ofFramed;
  177.     Insert(FileView);
  178.  
  179.     Inc(Bounds.A.X, 2);
  180.     Bounds.A.Y := Bounds.B.Y + 1;
  181.     Bounds.B.Y := Bounds.A.Y + 1;
  182.     Insert(New(PCntView, Init(Bounds)));
  183.  
  184.     Bounds.Move(0,1);
  185.     Insert(New(PTagView, Init(Bounds)));
  186.  
  187.     SelectNext(False);
  188.   end;
  189.  
  190.   { decide where to place this window }
  191.   TopWin := Message(Desktop, evBroadcast, cmTopWindow, nil);
  192.   if TopWin <> nil then
  193.   begin
  194.     W^.MoveTo(TopWin^.Origin.X + 1, TopWin^.Origin.Y + 1);
  195.     W^.GrowTo(TopWin^.Size.X, TopWin^.Size.Y);
  196.   end
  197.   else
  198.     W^.MoveTo(2,1);
  199.  
  200.   if Application^.ValidView(W) <> nil then
  201.   begin
  202.     Desktop^.Insert(W);
  203.     Message(Desktop, evBroadcast, cmNewDir, PRoot);
  204.   end;
  205.  
  206.   Dispose(D, Done);
  207. end;
  208.  
  209. end.
  210.